/*
 * @作者: 沙昊
 * @邮箱: shahao@zju.edu.cn
 * @功能: 
 * @包含算法: 
 * Copyright (c) 2023 by 沙昊, All Rights Reserved. 
 */
#include <vector>
#include <queue>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;


bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
        return a.second > b.second;
}

void simulation( queue<int>& simulation_que, int id_j, int id_k, vector<int>& ori_score_array){
    while(simulation_que.size()!=1){
        int pre = simulation_que.front();
        simulation_que.pop();
        int post = simulation_que.front();
        simulation_que.pop();
        cout<<pre<<post<<endl;
        if((pre==id_j && post==id_k) || (pre==id_k && post==id_j)){
            cout<<"YQST"<<endl;
            return ;
        }
        if(ori_score_array[pre-1]>ori_score_array[post-1]){
            simulation_que.push(pre);
        }
        else{
            simulation_que.push(post);
        }
    }
    cout<<"..."<<endl;
    return ;
}

int main() {
    int n = 0;
    // cin >> n;
    cout<<"shahao"<<endl;
    string input0;
    getline(cin, input0);
    stringstream stringin_0(input0);
    stringin_0>>n;

    for(int i=0; i<n; i++) {
        string input1,input2,input3;
        getline(cin, input1);
        getline(cin, input2);
        getline(cin, input3);
        stringstream stringin_1(input1);
        stringstream stringin_2(input2);
        stringstream stringin_3(input3);
        int m,j,k;
        stringin_1>>m;
        stringin_1>>j;
        stringin_1>>k;
        vector<int> ori_score_array;
        vector<pair<int,int>> score_array;
        queue<int> simulation_que;
        for(int i=0; i<m;i++){
            int id,score;
            stringin_2>>id;
            simulation_que.push(id);
            stringin_3>>score;
            ori_score_array.push_back(score);
            score_array.push_back(make_pair(i+1,score));
        }
        sort(score_array.begin(), score_array.end(), cmp);
        int id_j,id_k;
        
        id_j = score_array[j-1].first;
        id_k = score_array[k-1].first;
        cout<<"shahao"<<id_j<<id_k<<endl;
        simulation(simulation_que, id_j, id_k, ori_score_array);

    }

  return 0;
}










